#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 6e5 + 10;
const int mod = 1e9 + 7;

int upd(int x) { return x + (x >> 31 & mod); }

ll qp(ll x,int t) { ll res = 1; for(;t;t >>= 1,x = x * x % mod) if(t & 1) res = res * x % mod; return res; }

int n,m,tot;
int pw[N],ipw[N],a[N],cv[N],pos[N];

struct pott { int val,*p; } b[N];

struct node { int ans,val1,val2,s; node(int x = 0,int y = 0) { ans = 0; val1 = x; val2 = (ll) x * ipw[1] % mod; s = y; } } val[N << 2];

node operator + (node a,node b) {
	node c; c.ans = upd(a.ans + (ll) b.ans % mod - mod); c.ans = upd(c.ans + (ll) a.val1 * b.val2 % mod * ipw[a.s] % mod - mod);
	c.val1 = upd(a.val1 + (ll) b.val1 * pw[a.s] % mod - mod); c.val2 = upd(a.val2 + (ll) b.val2 * ipw[a.s] % mod - mod);
	c.s = a.s + b.s; return c;
}

void upd(int pos,int v,int o = 1,int l = 1,int r = tot) {
	if(l == r) return val[o] = node(b[l].val * v,v),void(); int mid = l + r >> 1; 
	if(pos <= mid) upd(pos,v,o << 1,l,mid); else upd(pos,v,o << 1 | 1,mid + 1,r);
	val[o] = val[o << 1] + val[o << 1 | 1];
}

inline void getans() { printf("%d\n",val[1].ans); }

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in; for(int i = 1;i <= n;i++) b[++tot].val = a[i] = in,b[tot].p = a + i;
	m = in; for(int i = 1;i <= m;i++) pos[i] = in,b[++tot].val = cv[i] = in,b[tot].p = cv + i;
	sort(b + 1,b + tot + 1,[](pott a,pott b) { return a.val < b.val; });
	for(int i = 1;i <= tot;i++) *b[i].p = i;
	for(int i = (pw[0] = 1);i <= n;i++) pw[i] = pw[i - 1] * 2ll % mod; ipw[n] = qp(pw[n],mod - 2);
	for(int i = n - 1;i >= 0;i--) ipw[i] = ipw[i + 1] * 2ll % mod;
	for(int i = 1;i <= n;i++) upd(a[i],1); getans();
	for(int i = 1;i <= m;i++) {
		upd(a[pos[i]],0); upd(cv[i],1); a[pos[i]] = cv[i];
		getans();
	}
	return 0;
}
